package com.wanxi.education.util;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;

/**
 * @Author: 寇文宝
 * @Description: 订单编号生成类
 * @Date: Created in 2021/9/24
 * @Version: 1.0
 */

public class GenerateOrderNoUtil {
    private static String date;

    public static synchronized String getOrderNo() {
        String str = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
        if (date == null || !date.equals(str)) {
            date = str;
        }
        int random = new Random().nextInt(9000) + 100;//为变量赋随机值1000-9999;
        long orderNo = Long.parseLong((date)) * 10000;
        orderNo += random;
        return orderNo + "";
    }

}
